﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Net;
using System.Text;
using System.IO;
using System.Web.Services;
using System.Data.SqlClient;
using System.Drawing;


namespace jnxcLogin
{
    public partial class Default : System.Web.UI.Page
    {
        PagedDataSource pds = new PagedDataSource();
        PagedDataSource pds1 = new PagedDataSource();
        //Weather.WeatherWebServiceSoapClient w = new Weather.WeatherWebServiceSoapClient("WeatherWebServiceSoap");
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["diqu"] = "";
            Session["jibie"] = "";

            if (!IsPostBack == true)
            {
                Label3.Text = "林业有害生物信息服务平台";
                pds.AllowPaging = false;
                DataSet set = new DataSet();
                SqlConnection conn = DB.createCon();
                conn.Open();
                SqlDataAdapter adapter = new SqlDataAdapter("select top 5 * from News_Table where NewsStyle='新闻' order by NewsId desc", conn);
                adapter.Fill(set);
                pds.DataSource = set.Tables[0].DefaultView;
                DataList1.DataSource = pds;
                DataList1.DataBind();

                pds1.AllowPaging = false;
                DataSet set1 = new DataSet();
                SqlConnection conn1 = DB.createCon();
                conn1.Open();
                SqlDataAdapter adapter1 = new SqlDataAdapter("select top 5 * from News_Table where NewsStyle='通知' order by NewsId desc", conn1);
                adapter1.Fill(set1);
                pds1.DataSource = set1.Tables[0].DefaultView;
                DataList2.DataSource = pds1;
                DataList2.DataBind();
                conn1.Close();

                SqlCommand cmd = new SqlCommand("select * from S_Province", conn);
                SqlDataReader sdr = cmd.ExecuteReader();
                this.DropDownList1.DataSource = sdr;
                this.DropDownList1.DataTextField = "ProvinceName";
                this.DropDownList1.DataValueField = "ProvinceID";
                this.DropDownList1.DataBind();
                sdr.Close();

                SqlCommand cmd1 = new SqlCommand("select * from S_City where ProvinceID=0 or ProvinceID=1", conn);
                SqlDataReader sdr1 = cmd1.ExecuteReader();
                this.DropDownList2.DataSource = sdr1;
                this.DropDownList2.DataTextField = "CityName";
                this.DropDownList2.DataValueField = "CityID";
                this.DropDownList2.DataBind();
                sdr1.Close();
                conn.Close();
            }
            //Ajax.Utility.RegisterTypeForAjax(typeof(WebForm2));
        }
        //[Ajax.AjaxMethod()]
        //public string GetCity(string ParentID)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    sb.AppendFormat("<option  value=\"1\">--请选择--</option> ");
        //    DataTable dt = DB1.Query(string.Format("select * from Province where ParentID={0} ", ParentID)).Tables[0];
        //    foreach (DataRow dr in dt.Rows)
        //    {
        //        sb.AppendFormat(" <option  value=\"{0}\">{1}</option>\n", dr["ID"], dr["CityName"]);
        //    }
        //    return sb.ToString();
        //}
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            SqlConnection con = DB.createCon();
            con.Open();
            SqlCommand cmd1 = new SqlCommand("select * from S_City where ProvinceID=0 or ProvinceID='" + DropDownList1.SelectedValue + "'", con);
            SqlDataReader sdr1 = cmd1.ExecuteReader();
            this.DropDownList2.DataSource = sdr1;
            this.DropDownList2.DataTextField = "CityName";
            this.DropDownList2.DataValueField = "CityID";
            this.DropDownList2.DataBind();
            sdr1.Close();
            SqlCommand cmd2 = new SqlCommand("select * from S_District where CityID=0", con);
            SqlDataReader sdr2 = cmd2.ExecuteReader();
            this.DropDownList3.DataSource = sdr2;
            this.DropDownList3.DataTextField = "DistrictName";
            this.DropDownList3.DataValueField = "DistrictID";
            this.DropDownList3.DataBind();
            sdr2.Close();
            con.Close();
           
        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            SqlConnection con = DB.createCon();
            con.Open();
            SqlCommand cmd1 = new SqlCommand("select * from S_District where CityID=0 or CityID='" + DropDownList2.SelectedValue + "'", con);
            SqlDataReader sdr1 = cmd1.ExecuteReader();
            this.DropDownList3.DataSource = sdr1;
            this.DropDownList3.DataTextField = "DistrictName";
            this.DropDownList3.DataValueField = "DistrictID";
            this.DropDownList3.DataBind();
            sdr1.Close();
            con.Close();
           
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {

            if (DropDownList1.SelectedItem.Text != "---请选择---")
            {
                DataSet set = new DataSet();
                SqlConnection conn = DB.createCon();
                conn.Open();
                SqlDataAdapter adapter = new SqlDataAdapter("select top 5 * from News_Table where shengji='" + DropDownList1.SelectedItem.Text + "'and NewsStyle='新闻' order by NewsId desc", conn);
                adapter.Fill(set);
                pds.DataSource = set.Tables[0].DefaultView;
                DataList1.DataSource = pds;
                DataList1.DataBind();
                conn.Close();

                pds1.AllowPaging = false;
                DataSet set1 = new DataSet();
                SqlConnection conn1 = DB.createCon();
                conn1.Open();
                SqlDataAdapter adapter1 = new SqlDataAdapter("select top 5 * from News_Table where shengji='" + DropDownList1.SelectedItem.Text + "'and NewsStyle='通知' order by NewsId desc", conn1);
                adapter1.Fill(set1);
                pds1.DataSource = set1.Tables[0].DefaultView;
                DataList2.DataSource = pds1;
                DataList2.DataBind();
                conn1.Close();
                if (DropDownList2.SelectedItem.Text == "---请选择---")
                {
                    Label3.Text = DropDownList1.SelectedItem.Text + "林业有害生物信息服务平台";
                    Label4.Text = DropDownList1.SelectedItem.Text;
                    Label5.Text = DropDownList1.SelectedItem.Text + "森林病虫害防治检疫站"; ;
                    Session["jibie"] = "1";
                }
                else
                {
                    if (DropDownList3.SelectedItem.Text == "---请选择---")
                    {
                        Label3.Text = DropDownList2.SelectedItem.Text + "林业有害生物信息服务平台";
                        Label4.Text = DropDownList2.SelectedItem.Text;
                        Label5.Text = DropDownList2.SelectedItem.Text + "森林病虫害防治检疫站"; ;
                       
                        //Session["jibie"] = "2";
                    }
                    else
                    {
                        Label3.Text = DropDownList3.SelectedItem.Text + "林业有害生物信息服务平台";
                        Label4.Text = DropDownList3.SelectedItem.Text;
                        Label5.Text = DropDownList3.SelectedItem.Text + "森林病虫害防治检疫站";
                       
                        //Session["jibie"] = "3";
                    }

                }
            }
            else
            {
                Label3.Text = "林业有害生物信息服务平台";
                Label4.Text = "";
                Label5.Text = "森林病虫害防治检疫站";
                //Session["jibie"] = "";
            }

            //Session["diqu"] = Label4.Text;

            Session["title"] = this.Label3.Text;
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            //Session["11"] = DropDownList1.SelectedItem.Text;
            Response.Redirect("xinxiliebiao.aspx");
        }
      
    }
}